//
//  VipInfoCardTableViewCell.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/27.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "VipInfoCardTableViewCell.h"

@implementation VipInfoCardTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        
        self.bgNameArray = [NSMutableArray arrayWithObjects:@"smallcard_cz",@"smallcard_c",@"smallcard_qx", nil];
        
        /**
         背景
         */
        UIImageView *bgView = [[UIImageView alloc] init];
        bgView.layer.cornerRadius = 4;
        bgView.layer.masksToBounds = YES;
        bgView.backgroundColor = CSWhiteColor;
        [self.contentView addSubview:bgView];
        self.bgView = bgView;
        
        /**
         线
         */
        UIView *suView = [[UILabel alloc] init];
        suView.backgroundColor = ButtonBackGroundColor;
        [self.contentView addSubview:suView];;
        self.suView = suView;
        
        /**
         卡类型
         */
        UILabel *classLabel = [[UILabel alloc] init];
        classLabel.font = BoldMidBigFont;
        classLabel.textColor = ButtonBackGroundColor;
        classLabel.text = @"储值类型（315055）";
        [self.contentView addSubview:classLabel];;
        self.classLabel = classLabel;
        
        /**
         余额
         */
        UILabel *balanceDetailLabel = [[UILabel alloc] init];
        balanceDetailLabel.font = SmallFont;
        balanceDetailLabel.textColor = ButtonBackGroundColor;
        balanceDetailLabel.text = @"余额：100";
        [self.contentView addSubview:balanceDetailLabel];;
        self.balanceDetailLabel = balanceDetailLabel;
        
        /**
         线
         */
        UIView *sepView = [[UILabel alloc] init];
        sepView.backgroundColor = BackGroundColor;
        [self.contentView addSubview:sepView];;
        self.sepView = sepView;
        
        /**
         卡号
         */
        UILabel *cardNum = [[UILabel alloc] init];
        cardNum.font = MidBigFont;
        cardNum.textColor = BlackColor;
        cardNum.text = @"卡号：10086";
        [self.contentView addSubview:cardNum];;
        self.cardNum = cardNum;
        
        /**
         名字
         */
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.font = MidBigFont;
        nameLabel.textColor = BlackColor;
        nameLabel.text = @"绑定会员：暗暗";
        [self.contentView addSubview:nameLabel];;
        self.nameLabel = nameLabel;
        
        /**
         有效期
         */
        UILabel *timeLable = [[UILabel alloc] init];
        timeLable.font = MidBigFont;
        timeLable.textColor = BlackColor;
        timeLable.text = @"有 效 期：2017-09-09至2018-01-01";
        [self.contentView addSubview:timeLable];;
        self.timeLabel = timeLable;
        
        /**
         地址
         */
        UILabel *addressLable = [[UILabel alloc] init];
        addressLable.font = MidBigFont;
        addressLable.textColor = BlackColor;
        addressLable.text = @"场地：艺术中心店";
        [self.contentView addSubview:addressLable];;
        self.addressLabel = addressLable;
        
        /**
         地址
         */
        UIImageView *next = [[UIImageView alloc] init];
        next.image = [UIImage imageNamed:@"xiayibu"];
        [self.contentView addSubview:next];;
        self.nextImage = next;
        
        //card_icon_overdue
        UIImageView *overImageView = [[UIImageView alloc] init];
        overImageView.image = [UIImage imageNamed:@"card_icon_overdue"];
        overImageView.hidden = YES;
        [self.contentView addSubview:overImageView];
        self.overImageView = overImageView;
        
        
        
        
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     背景
     */
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.mas_equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 15, 10, 15));
    }];
    
    /**
     竖线
     */
    [self.suView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.classLabel);
        
        make.left.mas_equalTo(self.bgView).offset(10);
        
        make.width.mas_equalTo(2);
        
        make.height.mas_equalTo(20);
        
    }];
    
    /**
     卡类型
     */
    [self.classLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.bgView).offset(15);
        
        make.left.mas_equalTo(self.suView.mas_right).offset(5);
        
    }];
    
    /**
     余额
     */
    [self.balanceDetailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.bgView).offset(-10);
        
        make.centerY.mas_equalTo(self.classLabel);
    }];
    
    /**
     分割线
     */
    [self.sepView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.bgView).offset(5);
        
        make.right.mas_equalTo(self.bgView).offset(-5);
        
        make.height.mas_equalTo(1);
        
        make.top.mas_equalTo(self.classLabel.mas_bottom).offset(10);
    }];
    
    /**
     卡号
     */
    [self.cardNum mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.sepView.mas_bottom).offset(10);
        
        make.left.mas_equalTo(self.suView);
        
    }];
    
    /**
     名字
     */
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.cardNum.mas_bottom).offset(5);
        
        make.left.mas_equalTo(self.suView);
        
    }];
    
    /**
     有效时间
     */
    [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(5);
        
        make.left.mas_equalTo(self.suView);
        
    }];
    
    
    /**
     场地
     */
    [self.addressLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(5);
        
        make.left.mas_equalTo(self.suView);
        
        make.bottom.mas_equalTo(self.bgView).offset(-35);
    }];
    
    /**
     下一步
     */
    [self.nextImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.bgView).offset(-5);
        
        make.centerY.mas_equalTo(self.bgView);
        
    }];
    
    [self.overImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.bgView);
        
        make.right.mas_equalTo(self.bgView).offset(-3);
    }];
}

-(void)layoutSubviews{

    
}


-(void)setSelectRow:(NSInteger)selectRow{
    
    self.bgView.image = [UIImage imageNamed:self.bgNameArray[1]];
    
//    //黑色
//    if (selectRow % 3 == 0) {
//
//        /**
//         卡类型
//         */
//        self.classLabel.textColor = CSWhiteColor;
//
//        /**
//         名字
//         */
//
//        self.nameLabel.textColor = CSWhiteColor;
//
//        /**
//         余额
//         */
//        self.balanceLabel.textColor = CSWhiteColor;
//
//    }
//    else{
//
//        /**
//         卡类型
//         */
//        self.classLabel.textColor = CSBlackColor;
//
//        /**
//         名字
//         */
//
//        self.nameLabel.textColor = CSBlackColor;
//
//        /**
//         余额
//         */
//        self.balanceLabel.textColor = CSBlackColor;
//    }
}

-(void)setVipCardModel:(VipCardModel *)vipCardModel{
    
    //卡号
    self.cardNum.text = [NSString stringWithFormat:@"卡号：%@",vipCardModel.MemberCardNum];
    
    
    //会员名字
    NSString *memberName = [NSString stringWithFormat:@"绑定会员：%@",vipCardModel.MemberName];
    
    
    self.nameLabel.text = memberName;
    
    //有效期
    self.timeLabel = [NSString stringWithFormat:@"有 效 期：%@至%@",vipCardModel.JoinTime,vipCardModel.EndTime];
    
    //场地
    self.addressLabel = [NSString stringWithFormat:@"场地：%@",[vipCardModel.ShopName componentsJoinedByString:@","]];
    
    int MemberCardType = [vipCardModel.MemberCardType intValue];
    
    //次卡储值类型（315055）
    if (MemberCardType == Time) {
        
        self.classLabel.text = [NSString stringWithFormat:@"%@",vipCardModel.MemberCardName];
        
        self.balanceDetailLabel.text = [NSString stringWithFormat:@"%@次",vipCardModel.Times];
    }
    //期限卡
    else if (MemberCardType == Term) {
        
        self.classLabel.text = [NSString stringWithFormat:@"%@",vipCardModel.MemberCardName];
        
        NSString *endTime = vipCardModel.EndTime;
        
        NSDateComponents *components = [NSString getDateDifference:endTime];
        
        self.balanceDetailLabel.text = [NSString stringWithFormat:@"%ld天",labs(components.day)];
    }
    //储值
    else{
        
       self.classLabel.text = [NSString stringWithFormat:@"%@",vipCardModel.MemberCardName];
        
        self.balanceDetailLabel.text = [NSString stringWithFormat:@"%@元",vipCardModel.TotalFee];
    }
    
    if ([vipCardModel.Status intValue] == 4003) {
        
        self.overImageView.hidden = NO;
    }
    else{
        
        self.overImageView.hidden = YES;
    }
}


- (void)drawRect:(CGRect)rect
{
//    CGContextRef context =UIGraphicsGetCurrentContext();
//    
//    CGContextBeginPath(context);
//    
//    CGContextSetLineWidth(context,1.0);//线宽度
//    
//    CGContextSetStrokeColorWithColor(context,LineBackGroundColor.CGColor);
//    
//    CGContextMoveToPoint(context,0,rect.size.height);
//    
//    CGContextAddLineToPoint(context,SCREEN_WIDTH,rect.size.height);
//    
//    CGContextStrokePath(context);
}

@end
